import Vue from 'vue'
import Vuex from 'vuex'
import VueRouter from 'vue-router'
import {
  build,
  dev,
  version,
  title
} from '../config'
import mk from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import 'element-ui/lib/theme-chalk/mk.css'
import 'element-ui/lib/theme-chalk/fonts/iconfont.css'
import routerConfig from './router/'
import 'babel-polyfill'
import 'animate.css'

// 环境
const productMode = process.env.NODE_ENV === 'production'
const config = productMode === true ? build : dev
Vue.use(Vuex)
const store = new Vuex.Store(mk.MkStore)
mk.MkStore.transform(store, {
  basePath: config.path,
  baseTitle: title,
  index: routerConfig.index,
  wsPath: config.wspath,
  token: config.token,
  viewAction: config.viewAction,
  uploadAction: config.uploadAction
})
Vue.use(VueRouter)
const router = new VueRouter(routerConfig)

// region interceptors
Vue.use(mk, {
  baseURL: config.path,
  timeout: 50000,
  productMode,
  productErrorTip: 'sorry，系统发生错误！',
  defaultTip: '未知错误',
  sessionTimeoutCode: '201001',
  loginPath: routerConfig.login,
  systemErrorCodeStartWith: 1,
  version,
  router,
  store
})
// 初始化
new Vue({
  el: '#app',
  router,
  store
})
